define(function(require, exports, module) {
    require('basic');
    require('jquerytmpl');
    var config = require('config');
    var user = require('user');

    var model = function(){
        this.init();
        //console.log(config.login)
    };

    model.prototype ={
        init: function(){
            this.addEvents();
            this.loadList();
        },
        /**
         * [loadList /repo/list ]
         * @return {[type]} [description]
         */
        loadList: function(){
            var sf = this;
            var data_str = user.info.leadPost;
            $.ajax({
                type: "GET",
                url: config.repo_list+data_str,
                dataType: 'json',
                success: function(data){
                    var data_arr = [];
                    var sub_data_obj = {}
                    for(var i=0;i<data.length;i++){
                        var t1 = data[i],
                            d1 = data[i]['services'];
                        for(var o=0;o<d1.length;o++){
                            var t2 = d1[o],
                            d2 = d1[o]['items'];
                            for(var e=0;e<d2.length;e++){
                                var t3 = d2[e],
                                    obj = {};
                                obj['type'] = t1['type'];
                                obj['service'] = t2['service'];
                                obj['version'] = t3['version'];
                                sub_data_obj['all'] = sub_data_obj['all'] ? sub_data_obj['all'] : [];
                                sub_data_obj['all'].push(obj);
                                sub_data_obj[t1['type']] = sub_data_obj[t1['type']] ? sub_data_obj[t1['type']] : [];
                                sub_data_obj[t1['type']].push(obj);
                          }
                        }
                    }
                    $("#repoListTemplate").tmpl(sub_data_obj.all).appendTo("#repo_list tbody");
                    $("#repoListTemplateDB").tmpl(sub_data_obj.DB).appendTo("#repo_list_db tbody");
                    $("#repoListTemplateMQ").tmpl(sub_data_obj.MQ).appendTo("#repo_list_mq tbody");
                    $("#repoListTemplateMiddleware").tmpl(sub_data_obj.Middleware).appendTo("#repo_list_middleware tbody");
                    $("#repoListTemplateWeb").tmpl(sub_data_obj.web).appendTo("#repo_list_web tbody");
                } 
            });
        },
        
        /**
         * [checkAll 全选动作]
         * @param  {[jqobj]} _wrap [description]
         * @return {[type]}       [description]
         */
        checkAll: function(_wrap){
            _wrap.find('input.checked_all').each(function(){
                $(this).removeAttr('checked');
                $(this).change(function(e) {
                    var bl = $(this).prop('checked');
                    _wrap.find('input.form_checkbox').prop({checked:bl});
                });
            });
        },
        
        /**
         * [addEvents 各步骤上一步下一步的事件,.done是最后提交按钮]
         */
        addEvents: function(){
            var sf = this;
        }
    };
    

    module.exports = new model();

    
});

